package com.darrenchan.spark.rdd

import org.apache.spark.{SparkConf, SparkContext}
import com.alibaba.fastjson.JSONObject

object SparkCoreApp2 {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[2]").setAppName("WordCountApp")
    val sc = new SparkContext(sparkConf)

    //业务逻辑
    val counts = sc.textFile("hello.txt").
      flatMap(_.split(" ")).
      map((_, 1)).
      reduceByKey(_+_)




//    counts.saveAsTextFile("D:\\hello\\output")

    println(counts.collect().mkString("\n"))
//    counts.checkpoint()
    sc.stop()
  }
}
